<?php
/**
 * Created by PhpStorm.
 * User: tsy
 * Date: 2016/7/14
 * Time: 11:10
 */
namespace Admin\Model;
use Think\Model;

class RoleModel extends Model{
    protected $trueTableName = 'bypal_comm_role';

    /**
     * 查询角色
     * @return mixed
     */
    public function select_role(){
        $sql="select role_id,role_name,role_code from bypal_comm_role";
        $Model = new \Think\Model();
        $values=$Model->query($sql);
        return $values;
    }

    /**
     * 用户新增角色
     * @param $array
     * @return false|int
     */
    public function add_user_role($array){
        $sql="insert into bypal_comm_userrole(user_id,role_id) values('".$array['user_id']."','".$array['role_id']."')";
        $Model= new \Think\Model();
        $values=$Model->execute($sql);
        return $values;
    }

    public function select_find_by_code($role_code,$role_id){
        $sql="select role_id,role_name from bypal_comm_role where role_code='$role_code'";

        if($role_id!=''){
            $sql.=" and role_id!=$role_id";
        }

        $Model= new \Think\Model();
        $values=$Model->query($sql);
        return $values;
    }

    public function select_find_by_id($role_id){
        $sql="select role_id,role_name,role_code from bypal_comm_role where role_id='$role_id'";
        $Model= new \Think\Model();
        $values=$Model->query($sql);
        return $values;
    }
}